From 64342d9ec48f823b48233f58c930ba7472dc3979 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Fri, 18 Jul 2008 11:24:13 +0100 Subject: [PATCH] x86: Fix APERF/MPERF query bug on non-current cpu Currently xen hypervisor cpufreq can only query APERF/MPERF on running cpu, which will result in system broken when query on non-current cpu. This patch fix the APERF/MPERF query bug on non-current cpu. Signed-off-by: Liu Jinsong --- xen/arch/x86/acpi/cpufreq/cpufreq.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufreq/cpufreq.c index cabe94ea93..58147da55b 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -237,9 +237,9 @@ static u32 get_cur_val(cpumask_t mask) * Only IA32_APERF/IA32_MPERF ratio is architecturally defined and * no meaning should be associated with absolute values of these MSRs. */ -/* FIXME: handle query on non-current cpu later */ -static unsigned int get_measured_perf(unsigned int cpu) +static void __get_measured_perf(void *perf_percent) { + unsigned int *ratio = perf_percent; union { struct { uint32_t lo; @@ -248,9 +248,6 @@ static unsigned int get_measured_perf(unsigned int cpu) uint64_t whole; } aperf_cur, mperf_cur; - unsigned int perf_percent; - unsigned int retval; - rdmsr(MSR_IA32_APERF, aperf_cur.split.lo, aperf_cur.split.hi); rdmsr(MSR_IA32_MPERF, mperf_cur.split.lo, mperf_cur.split.hi); @@ -264,10 +261,21 @@ static unsigned int get_measured_perf(unsigned int cpu) } if (aperf_cur.whole && mperf_cur.whole) - perf_percent = (aperf_cur.whole * 100) / mperf_cur.whole; + *ratio = (aperf_cur.whole * 100) / mperf_cur.whole; else - perf_percent = 0; + *ratio = 0; +} + +static unsigned int get_measured_perf(unsigned int cpu) +{ + unsigned int retval, perf_percent; + cpumask_t cpumask; + + if (!cpu_online(cpu)) + return 0; + cpumask = cpumask_of_cpu(cpu); + on_selected_cpus(cpumask, __get_measured_perf, (void *)&perf_percent,0,1); retval = drv_data[cpu]->max_freq * perf_percent / 100; return retval; -- 2.30.2